SNA Descritive Analysis from “Projeto Redes de Atenção às pessoas que consomem álcool e outras Drogas em Juiz de Fora-MG Brazil” - SNArRDJF
Here you can find a basic script to analysis data from SNArRDJF - this script was elaborated considering its use for orther matrix adjacency data from SNArRDJF - Here we are going to analyse:
########################## Basic Preparation ##### `#########################
rm(list = ls()) # removing previous objects to be sure that we don't have objects conflicts name
load("~/SNArRDJF/Robject/atividade_data.RData")
suppressMessages(library(RColorBrewer))
#suppressMessages(library(car))
#suppressMessages(library(xtable))
suppressMessages(library(igraph))
#suppressMessages(library(miniCRAN))
#suppressMessages(library(magrittr))
#suppressMessages(library(keyplayer))
#suppressMessages(library(dplyr))
#suppressMessages(library(feather))
#suppressMessages(library(visNetwork))
#suppressMessages(library(knitr))
suppressMessages(library(DT))
#In order to get dinamic javascript object install those ones. If you get problems installing go to Stackoverflow.com and type your error to discover what to do. In some cases the libraries need to be intalled in outside R libs.
#devtools::install_github("wch/webshot")
#webshot::install_phantomjs()
set.seed(123)
#atividade<-simplify(atividade) #Simplify
• For undirected graphs:
– Actor centrality - involvement (connections) with other actors
• For directed graphs:
– Actor centrality - source of the ties (outgoing edges)
– Actor prestige - recipient of many ties (incoming edges)
In general - high centrality degree means direct contact with many other actors
V(atividade)$indegree<-degree(atividade, mode = "in") # Actor prestige - recipient of many ties (incoming edges)
V(atividade)$outdegree <- degree(atividade, mode = "out") # Actor centrality - source of the ties (outgoing edges)
V(atividade)$totaldegree <- degree(atividade, mode = "total")
atividade_indegree<-degree(atividade, mode = "in")
atividade_outdegree<-degree(atividade, mode = "out")
atividade_totaldegree<-degree(atividade, mode = "total")
##in
summary(atividade_indegree)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.000 3.000 5.000 7.503 8.000 102.000
sd(atividade_indegree)
## [1] 10.02597
hist(degree(atividade, mode = "in", normalized = F), ylab="Frequency", xlab="Degree", breaks=vcount(atividade)/10, main="Histogram of Indegree Nodes - 27_ATIVIDADE")
##out
summary(atividade_outdegree)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.000 1.000 3.000 7.503 8.000 98.000
sd(atividade_outdegree)
## [1] 12.93548
hist(degree(atividade, mode = "out", normalized = F), ylab="Frequency", xlab="Degree", breaks=vcount(atividade)/10, main="Histogram of Outdegree Nodes - 27_ATIVIDADE")
##all
summary(atividade_totaldegree)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.00 5.00 9.00 15.01 15.00 200.00
sd(atividade_totaldegree)
## [1] 21.68457
hist(degree(atividade, mode = "all", normalized = F), ylab="Frequency", xlab="Degree", breaks=vcount(atividade)/10, main="Histogram of All Degree Nodes - 27_ATIVIDADE")
A slightly more nuanced metric is “strength centrality”, which is defined as the sum of the weights of all the connections for a given node. This is also sometimes called “weighted degree centrality”
V(atividade)$atividade_strength<- strength(atividade, weights=E(atividade)$weight)
atividade_strength<- strength(atividade, weights=E(atividade)$weight)
summary(atividade_strength)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.00 11.00 21.00 37.36 41.00 559.00
sd(atividade_strength)
## [1] 55.88722
hist(strength(atividade, weights=E(atividade)$weight), ylab="Frequency", xlab="Degree", breaks=vcount(atividade)/10, main="Histogram of Strength Degree Nodes - 27_ATIVIDADE")
V(atividade)$indegree_n<-degree(atividade, mode = "in", normalized = T)
V(atividade)$outdegree_n<- degree(atividade, mode = "out", normalized = T)
V(atividade)$totaldegree_n<- degree(atividade, mode = "total", normalized = T)
atividade_indegree_n<-degree(atividade, mode = "in", normalized = T)
atividade_outdegree_n<-degree(atividade, mode = "out", normalized = T)
atividade_totaldegree_n<-degree(atividade, mode = "total", normalized = T)
summary(atividade_indegree_n)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.00000 0.01613 0.02688 0.04034 0.04301 0.54840
sd(atividade_indegree_n)
## [1] 0.05390309
hist(degree(atividade, mode = "in", normalized = T), ylab="Frequency", xlab="Normalized Degree", breaks=vcount(atividade)/10, main="Histogram of Normalized Indegree Nodes - 27_ATIVIDADE")
summary(atividade_outdegree_n)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.000000 0.005376 0.016130 0.040340 0.043010 0.526900
sd(atividade_outdegree_n)
## [1] 0.06954558
hist(degree(atividade, mode = "out", normalized = T), ylab="Frequency", xlab="Normalized Degree", breaks=vcount(atividade)/10, main="Histogram of Normalized Outdegree Nodes - 27_ATIVIDADE")
summary(atividade_totaldegree_n)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.00000 0.02688 0.04839 0.08067 0.08065 1.07500
sd(atividade_totaldegree_n)
## [1] 0.1165837
hist(degree(atividade, mode = "all", normalized = T), ylab="Frequency", xlab="Normalized Degree", breaks=vcount(atividade)/10, main="Histogram of Normalized All Degree Nodes - 27_ATIVIDADE")
V(atividade)$atividade_centr_degree <- centralization.degree(atividade)$res
atividade_centr_degree <- centralization.degree(atividade)
atividade_centr_degree$centralization
## [1] 0.4999711
atividade_centr_degree$theoretical_max
## [1] 69192
atividade_degree.distribution<-degree.distribution(atividade)
summary(atividade_degree.distribution)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.000000 0.000000 0.000000 0.004975 0.000000 0.112300
sd(atividade_degree.distribution)
## [1] 0.0152431
hist(degree.distribution(atividade), breaks=vcount(atividade)/10, ylab="Frequency", xlab="Degree Distribuition", main="Histogram of Degree Distribuition - 27_ATIVIDADE")
dd <- degree.distribution(atividade, cumulative=T, mode="all")
plot(dd, pch=19, cex=1, col="orange", xlab="Degree", ylab="Cumulative Frequency", main= "Cumulative Frequency of 27_ATIVIDADE ")
dd.atividade <- degree.distribution(atividade)
d <- 1:max(degree(atividade))-1
ind <- (dd.atividade != 0)
plot(d[ind],
dd.atividade[ind],
log="xy",
col="blue",
xlab=c("Log-Degree"),
ylab=c("Log-Intensity"),
main="Log-Log Degree Distribution For 27_ATIVIDADE"
)
The neighborhood of a given order y of a vertex v includes all vertices which are closer to v than the order. Ie. order y=0 is always v itself, order 1 is v plus its immediate neighbors, order 2 is order 1 plus the immediate neighbors of the vertices in order 1, etc.
atividade_simplified<-simplify(atividade)
atividade_a.nn.deg <- graph.knn(atividade_simplified, weights =E(atividade_simplified)$weight)$knn %>% round(1)
V(atividade_simplified)$atividade_a.nn.deg <- graph.knn(atividade_simplified, weights=E(atividade_simplified)$weight)$knn
d<-cbind(V(atividade_simplified)$LABEL_COR,atividade_a.nn.deg)
datatable(d)
plot(degree(atividade_simplified),
atividade_a.nn.deg,
log="xy",
col="goldenrod",
xlab=c("Log Vertex Degree"),
ylab=c("Log Average Neighbor Degree"),
main="Average Neighbor Degree vs Vertex Degree - Log-Log Scale for 27_ATIVIDADE"
)
atividade_a.nn.deg_w <- graph.knn(atividade_simplified, weights=E(atividade_simplified)$weight)$knn %>% round(1)
V(atividade_simplified)$atividade_a.nn.deg_w <-atividade_a.nn.deg <- graph.knn(atividade_simplified, weights=E(atividade_simplified)$weight)$knn
summary(atividade_a.nn.deg_w)
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 3.00 31.72 53.35 60.25 84.25 173.20 1
sd(atividade_a.nn.deg_w, na.rm = T)
## [1] 36.03126
d<-cbind(V(atividade_simplified)$LABEL_COR,atividade_a.nn.deg_w)
datatable(d)
plot(degree(atividade_simplified),
atividade_a.nn.deg,
log="xy",
col="goldenrod",
xlab=c("Log Vertex Degree"),
ylab=c("Log Average Neighbor Degree"),
main="Average Weighted Neighbor Degree vs Vertex Degree - Log-Log Scale For Weighted 27_ATIVIDADE"
)
atividade_indegree<-degree(atividade, mode = "in")
atividade_outdegree<-degree(atividade, mode = "out")
atividade_totaldegree<-degree(atividade, mode = "total")
atividade_strength<- strength(atividade, weights=E(atividade)$weight)
atividade_indegree_n<-degree(atividade, mode = "in", normalized = T) %>% round(3)
atividade_outdegree_n<-degree(atividade, mode = "out", normalized = T) %>% round(3)
atividade_totaldegree_n<-degree(atividade, mode = "total", normalized = T) %>% round(3)
atividade_centr_degree <- centralization.degree(atividade)$res
atividade_a.nn.deg <- graph.knn(atividade_simplified)$knn %>% round(1)
atividade_a.nn.deg_w <- graph.knn(atividade_simplified, weights=E(atividade_simplified)$weight)$knn %>% round(1)
atividade_df_degree <- data.frame(atividade_indegree,
atividade_outdegree,
atividade_totaldegree,
atividade_indegree_n,
atividade_outdegree_n,
atividade_totaldegree_n,
atividade_strength,
atividade_centr_degree,
atividade_a.nn.deg,
atividade_a.nn.deg_w) %>% round(3)
#Adding type
atividade_df_degree <-cbind(atividade_df_degree, V(atividade)$LABEL_COR)
#Adding names
names(atividade_df_degree) <- c("In Degree", "Out Degree", "Total Degree","In Degree Normalized", "Out Degree Normalized", "Total Degree Normalized", "Strength","Centralization Degree","Average Neighbor Degree","Average Weighted Neighbor Degree","Type")
#Ordering Variables
atividade_df_degree<-atividade_df_degree[c("Type","In Degree", "Out Degree", "Total Degree","In Degree Normalized", "Out Degree Normalized", "Total Degree Normalized", "Strength","Centralization Degree","Average Neighbor Degree","Average Weighted Neighbor Degree")]
datatable(atividade_df_degree, filter = 'top')
aggdata_mean <-aggregate(atividade_df_degree, by=list(atividade_df_degree$Type), FUN=mean, na.rm=TRUE)
#Removing Type variable
aggdata_mean<-aggdata_mean[,-c(2)]
names(aggdata_mean) <- c("Group", "In Degree(M)", "Out Degree(M)", "Total Degree(M)","In Degree Normalized(M)", "Out Degree Normalized(M)", "Total Degree Normalized(M)", "Strength(M)","Centralization Degree(M)","Average Neighbor Degree(M)","Average Weighted Neighbor Degree(M)")
aggdata_sd <-aggregate(atividade_df_degree, by=list(atividade_df_degree$Type), FUN=sd, na.rm=TRUE)
#Removing Type variable
aggdata_sd<-aggdata_sd[,-c(2)]
names(aggdata_sd) <- c("Group", "In Degree(SD)", "Out Degree(SD)", "Total Degree(SD)","In Degree Normalized(SD)", "Out Degree Normalized(SD)", "Total Degree Normalized(SD)", "Strength(SD)","Centralization Degree(SD)","Average Neighbor Degree(SD)","Average Weighted Neighbor Degree(SD)")
total_table <- merge(aggdata_mean,aggdata_sd,by="Group")
#Rounding
Group<-total_table[,c(1)] #Keeping group
total_table<-total_table[,-c(1)] %>% round(2) #Rouding
total_table<-cbind(Group,total_table) #Binding toghter
#Organizing Variabels
total_table<-total_table[c("Group","In Degree(M)","In Degree(SD)", "Out Degree(M)", "Out Degree(SD)","Total Degree(M)", "Total Degree(SD)", "In Degree Normalized(M)", "In Degree Normalized(SD)", "Out Degree Normalized(M)", "Out Degree Normalized(SD)", "Total Degree Normalized(M)", "Total Degree Normalized(SD)", "Strength(M)","Strength(SD)", "Centralization Degree(M)","Centralization Degree(SD)","Average Neighbor Degree(M)","Average Neighbor Degree(SD)","Average Weighted Neighbor Degree(M)", "Average Weighted Neighbor Degree(SD)")]
datatable(total_table, filter = 'top')
atividade_df_degree <- data.frame(atividade_indegree,
atividade_outdegree,
atividade_totaldegree,
atividade_indegree_n,
atividade_outdegree_n,
atividade_totaldegree_n,
atividade_strength,
atividade_centr_degree,
atividade_a.nn.deg,
atividade_a.nn.deg_w) %>% round(3)
#Adding type
atividade_df_degree <-cbind(atividade_df_degree, V(atividade)$TIPO1)
#Adding names
names(atividade_df_degree) <- c("In Degree", "Out Degree", "Total Degree","In Degree Normalized", "Out Degree Normalized", "Total Degree Normalized", "Strength","Centralization Degree","Average Neighbor Degree","Average Weighted Neighbor Degree","Type")
#Ordering Variables
atividade_df_degree<-atividade_df_degree[c("Type","In Degree", "Out Degree", "Total Degree","In Degree Normalized", "Out Degree Normalized", "Total Degree Normalized", "Strength","Centralization Degree","Average Neighbor Degree","Average Weighted Neighbor Degree")]
datatable(atividade_df_degree, filter = 'top')
aggdata_mean <-aggregate(atividade_df_degree, by=list(atividade_df_degree$Type), FUN=mean, na.rm=TRUE)
#Removing Type variable
aggdata_mean<-aggdata_mean[,-c(2)]
names(aggdata_mean) <- c("Group", "In Degree(M)", "Out Degree(M)", "Total Degree(M)","In Degree Normalized(M)", "Out Degree Normalized(M)", "Total Degree Normalized(M)", "Strength(M)","Centralization Degree(M)","Average Neighbor Degree(M)","Average Weighted Neighbor Degree(M)")
aggdata_sd <-aggregate(atividade_df_degree, by=list(atividade_df_degree$Type), FUN=sd, na.rm=TRUE)
#Removing Type variable
aggdata_sd<-aggdata_sd[,-c(2)]
names(aggdata_sd) <- c("Group", "In Degree(SD)", "Out Degree(SD)", "Total Degree(SD)","In Degree Normalized(SD)", "Out Degree Normalized(SD)", "Total Degree Normalized(SD)", "Strength(SD)","Centralization Degree(SD)","Average Neighbor Degree(SD)","Average Weighted Neighbor Degree(SD)")
total_table <- merge(aggdata_mean,aggdata_sd,by="Group")
#Rounding
Group<-total_table[,c(1)] #Keeping group
total_table<-total_table[,-c(1)] %>% round(2) #Rouding
total_table<-cbind(Group,total_table) #Binding toghter
#Organizing Variabels
total_table<-total_table[c("Group","In Degree(M)","In Degree(SD)", "Out Degree(M)", "Out Degree(SD)","Total Degree(M)", "Total Degree(SD)", "In Degree Normalized(M)", "In Degree Normalized(SD)", "Out Degree Normalized(M)", "Out Degree Normalized(SD)", "Total Degree Normalized(M)", "Total Degree Normalized(SD)", "Strength(M)","Strength(SD)", "Centralization Degree(M)","Centralization Degree(SD)","Average Neighbor Degree(M)","Average Neighbor Degree(SD)","Average Weighted Neighbor Degree(M)", "Average Weighted Neighbor Degree(SD)")]
datatable(total_table, filter = 'top')
atividade_df_degree <- data.frame(atividade_indegree,
atividade_outdegree,
atividade_totaldegree,
atividade_indegree_n,
atividade_outdegree_n,
atividade_totaldegree_n,
atividade_strength,
atividade_centr_degree,
atividade_a.nn.deg,
atividade_a.nn.deg_w) %>% round(3)
#Adding type
atividade_df_degree <-cbind(atividade_df_degree, V(atividade)$TIPO2)
#Adding names
names(atividade_df_degree) <- c("In Degree", "Out Degree", "Total Degree","In Degree Normalized", "Out Degree Normalized", "Total Degree Normalized", "Strength","Centralization Degree","Average Neighbor Degree","Average Weighted Neighbor Degree","Type")
#Ordering Variables
atividade_df_degree<-atividade_df_degree[c("Type","In Degree", "Out Degree", "Total Degree","In Degree Normalized", "Out Degree Normalized", "Total Degree Normalized", "Strength","Centralization Degree","Average Neighbor Degree","Average Weighted Neighbor Degree")]
datatable(atividade_df_degree, filter = 'top')
aggdata_mean <-aggregate(atividade_df_degree, by=list(atividade_df_degree$Type), FUN=mean, na.rm=TRUE)
#Removing Type variable
aggdata_mean<-aggdata_mean[,-c(2)]
names(aggdata_mean) <- c("Group", "In Degree(M)", "Out Degree(M)", "Total Degree(M)","In Degree Normalized(M)", "Out Degree Normalized(M)", "Total Degree Normalized(M)", "Strength(M)","Centralization Degree(M)","Average Neighbor Degree(M)","Average Weighted Neighbor Degree(M)")
aggdata_sd <-aggregate(atividade_df_degree, by=list(atividade_df_degree$Type), FUN=sd, na.rm=TRUE)
#Removing Type variable
aggdata_sd<-aggdata_sd[,-c(2)]
names(aggdata_sd) <- c("Group", "In Degree(SD)", "Out Degree(SD)", "Total Degree(SD)","In Degree Normalized(SD)", "Out Degree Normalized(SD)", "Total Degree Normalized(SD)", "Strength(SD)","Centralization Degree(SD)","Average Neighbor Degree(SD)","Average Weighted Neighbor Degree(SD)")
total_table <- merge(aggdata_mean,aggdata_sd,by="Group")
#Rounding
Group<-total_table[,c(1)] #Keeping group
total_table<-total_table[,-c(1)] %>% round(2) #Rouding
total_table<-cbind(Group,total_table) #Binding toghter
#Organizing Variabels
total_table<-total_table[c("Group","In Degree(M)","In Degree(SD)", "Out Degree(M)", "Out Degree(SD)","Total Degree(M)", "Total Degree(SD)", "In Degree Normalized(M)", "In Degree Normalized(SD)", "Out Degree Normalized(M)", "Out Degree Normalized(SD)", "Total Degree Normalized(M)", "Total Degree Normalized(SD)", "Strength(M)","Strength(SD)", "Centralization Degree(M)","Centralization Degree(SD)","Average Neighbor Degree(M)","Average Neighbor Degree(SD)","Average Weighted Neighbor Degree(M)", "Average Weighted Neighbor Degree(SD)")]
datatable(total_table, filter = 'top')
#Set Seed
set.seed(123)
#Plotting based only on degree measures
edge.start <- ends(atividade, es=E(atividade), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(atividade))
maxC <- rep(Inf, vcount(atividade))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(atividade, niter=10000, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(atividade)$weight)
#PLotting
plot(atividade,
layout=co,
edge.color=V(atividade)$color[edge.start],
edge.arrow.size=(degree(atividade)+1)/(30*mean(degree(atividade))),
edge.width=E(atividade)$weight/(10*mean(E(atividade)$weight)),
edge.curved = TRUE,
vertex.size=log((degree(atividade)+2))*(0.5*mean(degree(atividade))),
vertex.frame.color="#ffffff",
vertex.label.color="black",
vertex.label=get.vertex.attribute(atividade,"LABEL_COR"),
vertex.label.cex=log(degree(atividade)+2)/mean(degree(atividade)),
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2]))
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(atividade)$LABEL_COR
b<-V(atividade)$color
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2], y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=2,
bty="n",
ncol=1,
lty=1,
cex = .5)
#Adding Title
title("Network Vertex Degree Sized - 27_ATIVIDADE", sub = "Source: from authors ", cex = .5)
text(x=range(co[,1])[1], y=range(co[,2])[1], labels =
sprintf("Median In Degree: %.2f\n Median Out Degree: %.2f",
median(degree(atividade, mode="in")),
median(degree(atividade, mode="out"))
))
#Set Seed
set.seed(123)
#Get Variable
V(atividade)$atividade_color_degree<-V(atividade)$totaldegree %>% round(0)
#Creating brewer pallette
vertex_atividade_color_degree<-
colorRampPalette(brewer.pal(length(unique(
V(atividade)$atividade_color_degree)), "RdBu"))(
length(unique(V(atividade)$atividade_color_degree)))
#Saving as Vertex properties
V(atividade)$vertex_atividade_color_degree<- vertex_atividade_color_degree[as.numeric(cut(degree(atividade),breaks =length(unique(V(atividade)$atividade_color_degree))))]
set.seed(123)
#Plotting based only on degree measures
edge.start <- ends(atividade, es=E(atividade), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(atividade))
maxC <- rep(Inf, vcount(atividade))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(atividade, niter=10000, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(atividade)$weight)
#PLotting
plot(atividade,
layout=co,
#edge.color=V(atividade)$color[edge.start],
edge.arrow.size=(degree(atividade)+1)/1000,
edge.width=E(atividade)$weight/10,
edge.curved = TRUE,
vertex.color=V(atividade)$vertex_atividade_color_degree,
vertex.size=log((degree(atividade)+2))*10,
vertex.size=20,
vertex.frame.color="#ffffff",
vertex.label.color="black",
vertex.label=get.vertex.attribute(atividade,"LABEL_COR"),
vertex.label.cex=log((degree(atividade)+2))/10,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2]))
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(atividade)$atividade_color_degree
b<-V(atividade)$vertex_atividade_color_degree
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
e<-e[order(e$a,decreasing=T),]
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2], y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=2,
bty="n",
ncol=1,
lty=1,
cex = .3)
#Adding Title
title("Network Vertex Degree Sized and Red to Blue - 27_ATIVIDADE", sub = "Source: from authors ")
text(x=range(co[,1])[1], y=range(co[,2])[1], labels =
sprintf("Median In Degree: %.2f\nMedian Out Degree: %.2f",
median(degree(atividade, mode="in")),
median(degree(atividade, mode="out"))
))
#Set Seed
set.seed(123)
#Get Variable
V(atividade)$atividade_color_degree<-V(atividade)$atividade_centr_degree
#Creating brewer pallette
vertex_atividade_color_degree<-
colorRampPalette(brewer.pal(length(unique(
V(atividade)$atividade_color_degree)), "Spectral"))(
length(unique(V(atividade)$atividade_color_degree)))
#Saving as Vertex properties
V(atividade)$vertex_atividade_color_degree<- vertex_atividade_color_degree[as.numeric(cut(V(atividade)$atividade_color_degree,breaks =length(unique(V(atividade)$atividade_color_degree))))]
#Plotting based only on degree measures
edge.start <- ends(atividade, es=E(atividade), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(atividade))
maxC <- rep(Inf, vcount(atividade))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(atividade, niter=10000, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(atividade)$weight)
#PLotting
plot(atividade,
layout=co,
edge.color=V(atividade)$vertex_atividade_color_degree[edge.start],
edge.arrow.size=(degree(atividade)+1)/10000,
edge.width=E(atividade)$weight/10,
edge.curved = TRUE,
vertex.color=V(atividade)$vertex_atividade_color_degree,
vertex.size=log((V(atividade)$atividade_centr_degree+2))*10,
vertex.frame.color="#ffffff",
vertex.label.color="black",
vertex.label=get.vertex.attribute(atividade,"LABEL_COR"),
vertex.label.cex=log((degree(atividade)+2))/10,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2]))
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(atividade)$atividade_color_degree
b<-V(atividade)$vertex_atividade_color_degree
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
e<-e[order(e$a,decreasing=T),]
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2], y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=2,
bty="n",
ncol=1,
lty=1,
cex = .3)
#Adding Title
title("Network Vertex Centralization Degree Sized Spectral Colored - 27_ATIVIDADE", sub = "Source: from authors ")
text(x=range(co[,1])[1], y=range(co[,2])[1], labels =
sprintf("Median In Degree: %.2f\nMedian Out Degree: %.2f",
median(degree(atividade, mode="in")),
median(degree(atividade, mode="out"))
))
#Set Seed
set.seed(123)
# Network elements with lower than meadian degree
higherthanmedian.network_atividade<-V(atividade)[degree(atividade)<median(degree(atividade))]
#Deleting vertices based in intersection betewenn atividade
high_atividade<-delete.vertices(atividade, higherthanmedian.network_atividade)
#Plotting based only on degree measures
edge.start <- ends(high_atividade, es=E(high_atividade), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(high_atividade))
maxC <- rep(Inf, vcount(high_atividade))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(high_atividade, niter=10000, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(high_atividade)$weight)
#PLotting
plot(high_atividade,
layout=co,
edge.color=V(high_atividade)$color[edge.start],
edge.arrow.size=(degree(high_atividade)+1)/1000,
edge.width=E(high_atividade)$weight/10,
edge.curved = TRUE,
vertex.size=log((V(high_atividade)$atividade_centr_degree+2))*10,
vertex.frame.color="#ffffff",
vertex.label.color="black",
vertex.label=get.vertex.attribute(high_atividade,"LABEL_COR"),
vertex.label.cex=log((degree(high_atividade)+2))/10,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2]))
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(high_atividade)$LABEL_COR
b<-V(high_atividade)$color
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2], y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=3,
bty="n",
ncol=1,
lty=1,
cex = .5)
#Adding Title
title("Network Higher Than Median Degree - 27_ATIVIDADE", sub = "Source: from authors ")
text(x=range(co[,1])[1], y=range(co[,2])[1], labels =
sprintf("Mean In Degree: %.2f\n Mean Out Degree: %.2f",
mean(degree(high_atividade, mode="in")),
mean(degree(high_atividade, mode="out"))
)
)
#Set Seed
set.seed(123)
# Network elements with lower than meadian degree
lowerthanmedian.network_atividade<-V(atividade)[degree(atividade)>median(degree(atividade))]
#Deleting vertices based in intersection betewenn atividade
small_atividade<-delete.vertices(atividade, lowerthanmedian.network_atividade)
#Plotting based only on degree measures
edge.start <- ends(small_atividade, es=E(small_atividade), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(small_atividade))
maxC <- rep(Inf, vcount(small_atividade))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(small_atividade, niter=10000, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(small_atividade)$weight)
#PLotting
plot(small_atividade,
layout=co,
edge.color=V(small_atividade)$color[edge.start],
edge.arrow.size=(degree(small_atividade)+1)/1000,
edge.width=E(small_atividade)$weight/10,
edge.curved = TRUE,
vertex.size=log((V(small_atividade)$atividade_centr_degree+2))*20,
vertex.frame.color="#ffffff",
vertex.label.color="black",
vertex.label=get.vertex.attribute(small_atividade,"LABEL_COR"),
vertex.label.cex=log((degree(small_atividade)+2))/3,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2]))
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(small_atividade)$LABEL_COR
b<-V(small_atividade)$color
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2], y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=4,
bty="n",
ncol=1,
lty=1,
cex = .5)
#Adding Title
title("Network Smaller Than Median Degree - 27_ATIVIDADE", sub = "Source: from authors ")
text(x=range(co[,1])[1], y=range(co[,2])[1], labels =
sprintf("Mean In Degree: %.2f\nMean Out Degree: %.2f",
mean(degree(small_atividade, mode="in")),
mean(degree(small_atividade, mode="out"))
)
)
#Set Seed
set.seed(123)
#Plotting based only on degree measures
edge.start <- ends(atividade_simplified, es=E(atividade_simplified), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(atividade_simplified))
maxC <- rep(Inf, vcount(atividade_simplified))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(atividade_simplified, niter=10000, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(atividade_simplified)$weight)
#Plotting based only on degree measures #atividade_simplified_a.nn.deg
V(atividade_simplified)$atividade_a.nn.deg<-as.numeric(graph.knn(atividade_simplified)$knn)
V(atividade_simplified)$atividade_a.nn.deg[V(atividade_simplified)$atividade_a.nn.deg=="NaN"]<-0
#PLotting
plot(atividade_simplified,
layout=co,
edge.color=V(atividade_simplified)$color[edge.start],
edge.arrow.size=sqrt((V(atividade_simplified)$atividade_a.nn.deg)^2+1)/1000,
edge.width=E(atividade_simplified)$weight/100,
edge.curved = TRUE,
vertex.color=V(atividade_simplified)$color,
vertex.size=(sqrt((V(atividade_simplified)$atividade_a.nn.deg)^2))/5,
vertex.frame.color="#ffffff",
vertex.label.color="black",
vertex.label=get.vertex.attribute(atividade_simplified,"LABEL_COR"),
vertex.label.cex=(sqrt((V(atividade_simplified)$atividade_a.nn.deg)^2)+1)/500,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2]))
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(atividade_simplified)$LABEL_COR
b<-V(atividade_simplified)$color
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2], y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=4,
bty="n",
ncol=1,
lty=1,
cex = .5)
#Adding Title
title("Network Average Neighbor Degree Sized - 27_ATIVIDADE", sub = "Source: from authors ")
text(x=range(co[,1])[1], y=range(co[,2])[1], labels =
sprintf("Median Average Neighbor Degree: %.2f",
median((atividade_a.nn.deg+1))
))
#Set Seed
set.seed(123)
#Plotting based only on degree measures
edge.start <- ends(atividade_simplified, es=E(atividade_simplified), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(atividade_simplified))
maxC <- rep(Inf, vcount(atividade_simplified))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(atividade_simplified, niter=10000, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(atividade_simplified)$weight)
#Plotting based only on degree measures #atividade_a.nn.deg
V(atividade_simplified)$atividade_a.nn.deg_w<-as.numeric(graph.knn(atividade_simplified, weights = E(atividade_simplified)$weight)$knn)
V(atividade_simplified)$atividade_a.nn.deg_w[V(atividade_simplified)$atividade_a.nn.deg_w=="NaN"]<-0
#PLotting
plot(atividade_simplified,
layout=co,
edge.color=V(atividade_simplified)$color[edge.start],
edge.arrow.size=sqrt((V(atividade_simplified)$atividade_a.nn.deg_w)^2+1)/1000,
edge.width=E(atividade_simplified)$weight/100,
edge.curved = TRUE,
vertex.color=V(atividade_simplified)$color,
vertex.size=(sqrt((V(atividade_simplified)$atividade_a.nn.deg_w)^2))/5,
vertex.frame.color="#ffffff",
vertex.label.color="black",
vertex.label=get.vertex.attribute(atividade_simplified,"LABEL_COR"),
vertex.label.cex=(sqrt((V(atividade_simplified)$atividade_a.nn.deg_w)^2)+1)/500,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2]))
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(atividade_simplified)$LABEL_COR
b<-V(atividade_simplified)$color
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2], y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=4,
bty="n",
ncol=1,
lty=1,
cex = .5)
#Adding Title
title("Network Average Weighted Neighbor Degree Sized - 27_ATIVIDADE", sub = "Source: from authors ")
text(x=range(co[,1])[1], y=range(co[,2])[1], labels =
sprintf("Median Average Weighted Neighbor Degree: %.2f",
median((atividade_a.nn.deg_w+1))
))
#Circle Degree ***Too intense computation***
#A_atividade <- get.adjacency(atividade, sparse=FALSE)
#detach("package:igraph", unload=TRUE)
#library(network)
#g <- network::as.network.matrix(A_atividade)
#library(sna)
#gplot.target(g, degree(g), main="Circle Degree")
#library(igraph)
save.image("~/SNArRDJF/Robject/atividade_data.RData")